{extend name="common/application" /}
{block name="title"}<title>搜索中心-服务商品搜索</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/service.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/search_work.css">
<link rel="stylesheet" type="text/css" href="_CSS_/scom.css"/>
<style type="text/css">
    .serviceItem {
        margin-right: 27px;
    }

    .selected {
        border: none;
        border-bottom: 1px solid #3377C1;
        margin-bottom: 0px;
    }
	.nodatas{display:block;}
</style>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
{/block}


{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix">
        {include file="/common/course" /}
        <!--筛选条件-->
        <div class="sortItem normalBox">
            <div class="sorts" style="margin-bottom: 10px;margin-top: 20px;">
                <label class="fl">商品分类：</label>
                <div class="serviceSort fl">
                    <div class="serviceBox mains fl">
                        <a class="mainSort" id="trade" href="javascript:;">
                            交易商品
                        </a>
                        <a class="mainSort" href="javascript:;" style="color: #3377c1">
                            服务商品
                        </a>

                    </div>
                </div>
            </div>

            <div class="sorts">
                <input type="hidden" id="index">
                <input type="hidden" id="value">
                <label class="fl">服务分类：</label>
                <div class="serviceSort fl">
                    <div class="serviceBox mains fl" value="1">
                        <a class="mainSort service" all="0" href="javascript:;" style="color: #3377c1">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            全部
                        </a>
                        <a class="mainSort service" all="1" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            专利评议
                        </a>
                        <a class="mainSort service" all="2" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            专利维权
                        </a>
                        <a class="mainSort service" all="3" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            专利托管
                        </a>
                        <a class="mainSort service" all="4" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            专利代理
                        </a>
                        <a class="mainSort service" all="5" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            政策应用
                        </a>
                        <a class="mainSort service" all="6" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            设计开发
                        </a>
                        <a class="mainSort service" all="7" href="javascript:;">
                            <span class="icons icon-unchecked hide"></span>
                            <span class="icons icon-checked hide"></span>
                            其他
                        </a>
                        <!--<div class="sendArea hide">-->
                        <!--<a class="sendBtn" href="javascript:;">提交</a>-->
                        <!--<a class="cancelBtn" href="javascript:;">取消</a>-->
                        <!--</div>-->
                    </div>
                    <!--<a class="checkmore" href="javascript:;">多选</a>-->
                </div>
            </div>
        </div>
        <!--服务列表-->
        <div class="serviceList sectionArea normalBox">
            <div class="leftCon" style="width: 1208px;">
                <div class="serviceHeader">
                    <div class="serviceNavi fl">
                        <a class="sortType active" value="0" href="javascript:;">综合排序</a>
                        <a class="sortType" value="1" href="javascript:;">成交量</a>
                        <a class="sortType" value="2" href="javascript:;">评价量</a>
                        <a class="sortType" value="3" href="javascript:;">时间</a>
                    </div>
                    <div class="priceRange fl">
                        <a class="showDiv fl" href="javascript:;">价格<span class="icons icon-arrowdown"></span></a>
                        <input class="minPrice" type="number" placeholder="￥"/>
                        <span class="fl">-</span>
                        <input class="maxPrice" type="number" placeholder="￥"/>
                        <div class="hideBox sortBox">
                            <a class="asc cur" href="javascript:;">按价格从低到高</a>
                            <a class="desc" href="javascript:;">按价格从高到低</a>
                        </div>
                        <a class="sendButton" href="javascript:;">确定</a>
                    </div>
                    <div class="total fr">
                        <p class="mr20">共<span class="num" id="count"></span>件商品</p>
                        <a class="prev" href="javascript:;">
                            <span class="icons icon-prev hide"></span>
                            <span class="icons icon-grey-prev"></span>
                        </a>
                        <p><span class="currentPage">1</span>/<span class="allPage"></span></p>
                        <a class="next" href="javascript:;">
                            <span class="icons icon-next"></span>
                            <span class="icons icon-grey-next hide"></span>
                        </a>
                    </div>
                </div>
                <div class="serviceArea">
                </div>
                <!--分页-->
                <div id="page"></div>
            </div>
        </div>
    </div>
</div>


{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/trading.js"></script>
<script type="text/javascript">
    $('#sel_1').addClass('selected');
    $("a.selectType").eq(0).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_work')}?" + keyword;
    });
    $("a.selectType").eq(1).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_trade')}?" + keyword;
    });
    $("a.selectType").eq(2).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_store')}?" + keyword;
    });
    $("a.selectType").eq(3).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_courses')}?" + keyword;
    });
    $("a.selectType").eq(4).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_persons')}?" + keyword;
    });
    $("a.selectType").eq(5).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_teachers')}?" + keyword;
    });
    $("a.selectType").eq(6).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_government')}?" + keyword;
    });


    $(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword);
		$("#keyword").val(keyword);
    });
  
    $('#trade').click(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_trade')}?" + keyword
    });


    $(".sortType").on('click', function () {
        var value = $(this).attr('value');
        var index = $("#index").val();
        $("#value").val(value);
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword, value, index);
    });
    $(".asc").click(function () {
        var index = $("#index").val();
        $("#value").val(4);
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword, 4, index);
    });
    $(".desc").click(function () {
        var index = $("#index").val();
        $("#value").val(5);
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword, 5, index);
    });
    $(".service").on('click', function () {
		$(".service").css('color','#666666');
		$(this).css('color','#3377c1');
        var index = $(this).attr('all');
        $("#index").val(index);
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var value = $("#value").val();
        postfile(1, keyword, value, index);
    });
    $(".sendButton").on('click', function () {
        var index = $("#index").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var value = $("#value").val();
        postfile(1, keyword, value, index);
    });

    $('.prev').on('click', function () {
        var index = $("#index").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var value = $("#value").val();
        var prev_num = parseInt($('.currentPage').html()) - 1;
        if (prev_num != 0) {
            postfile(prev_num, keyword, value, index);
        }
    });
    $('.next').on('click', function () {
        var index = $("#index").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var value = $("#value").val();
        var next_num = parseInt($('.currentPage').html()) + 1;
        var max_num = parseInt($('.allPage').html());
        if (next_num <= max_num) {
            postfile(next_num, keyword, value, index);
        }
    });

    function postfile(page, keyword, value, index) {
        var minmoney = $('.minPrice').val();
        var maxmoney = $('.maxPrice').val();
        $.ajax({
            type: 'get',
            url: "{:url('api/keyword/search_service')}",
            data: {
                'page': page,
                'keyword': keyword,
                'value': value,
                'type': index,
                'minmoney': minmoney,
                'maxmoney': maxmoney
            },
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    var re = /^[0-9]+$/;
                    $('.num').html(msg.data.count);
                    $('.currentPage').html(page);
                    var pages = Math.ceil(msg.data.count / 20);
                    $('.allPage').html(pages);
                    $("#count").html(msg.data.count);
                    //商品
                    if (msg.data.market.length != 0) {
                        var market = "";//商品
                        for (var i = 0; i < msg.data.market.length; i++) {
                            // if (i == 4 || i == 9 || i == 14 || i == 19) {
                            if (re.test((i + 1) / 5)) {
                                market += '<div class="serviceItem mr0">';
                            } else {
                                market += '<div class="serviceItem">';
                            }
							var price_num = number_format(msg.data.market[i].store, 2, ".", ",");
							var username = cut(msg.data.market[i].username,20);
                            market += '<a class="goDetails" href="/index.php/index' +
                                '/service/service_details.html?id=' + msg.data.market[i].id + '">' +
                                '<img src="/Images/serviceGoods/' + msg.data.market[i].image + '"/></a>' +
                                '<div class="serviceCon"><span class="prices">￥' + price_num + '</span>' +
                                '<a class="serviceTitle moreline" limit="24" href="/index.php/index' +
                                '/service/service_details.html?id=' + msg.data.market[i].id + '">' + username + '</a>' +
                                '<a class="company text_overflow" href="/index.php/index/trade/center.html?'+msg.data.market[i].s_id+'" ' +
                                'title="' + msg.data.market[i].name + '">' + msg.data.market[i].name + '</a>';
                            if (msg.data.market[i].rate >= 10000) {
                                var num = Math.floor(msg.data.market[i].rate / 10000);
                                market += '<p class="volume">成交量<span class="volumeNum">' + msg.data.market[i].value + '</span>笔</p>' +
                                    '<p class="assess fr">评价<span class="assessNum">' + num + '万+' + '</span>条</p></div></div>';
                            } else {
                                market += '<p class="volume">成交量<span class="volumeNum">' + msg.data.market[i].value + '</span>笔</p>' +
                                    '<p class="assess fr">评价<span class="assessNum">' + msg.data.market[i].rate + '</span>条</p></div></div>';
                            }
                        }

                        $(".serviceArea").html(market);
                        if (msg.data.market.length == 0) {
                            $('#page').html('');
                        } else {
                            $('#page').html(msg.data.render);
                            $("#pagination").delegate("a", "click", function () {
                                var num = $(this).attr("num");
                                var value = $("#value").val();
                                var index = $("#index").val();
								
								
                                if (num) {
                                    postfile(num, keyword, value, index);
                                }
                            });
							$("#GO").on('click',function(){
								var king = $("#go").val();
								if(king > pages){
									layer.alert("最多输入"+pages+"页");
									return;
								}
								postfile(king, c_id, category, value);
							});
                        }
                    } else {
                        var personnel = '<div class="nodatas">' +
                            '<img src="/static/web/images/nodata.png"/>' +
                            '<p>抱歉，找不到相关数据</p></div>';

                        $(".serviceArea").html(personnel);
                    }

                }
            }
        })
    }
</script>
{/block}